package com.xxrl.shop.controller;

import com.xxrl.shop.domain.User;
import com.xxrl.shop.domain.UserInfo;
import com.xxrl.shop.service.UserInfoService;
import org.springframework.web.bind.annotation.*;

/**
 * @author mis
 */
@RestController
@RequestMapping("/user/info")
public class UserInfoController {

    private final UserInfoService userInfoService;

    public UserInfoController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    @GetMapping("{id}")
    public UserInfo getUserInfo(@PathVariable Long id) {
        User user = new User(id);
        return userInfoService.getInfoByUser(user);
    }

    @PostMapping
    public void editUserInfo(UserInfo userInfo) {
        userInfoService.updateUserInfoByUser(new User(userInfo.getUser().getId()),userInfo);
    }
}
